package com.wwj.my_ummary.config.handlerInterceptor;


import com.wwj.my_ummary.config.filter.MyTestFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * @author admin007
 * 自定义拦截器
 */
//@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Resource
    private MyHandlerInterceptor myHandlerInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 自定义拦截器，添加拦截路径和排除拦截路径
        registry.addInterceptor(myHandlerInterceptor).addPathPatterns("/**").excludePathPatterns();
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**","/templates/**").addResourceLocations("classpath:/static/**","classpath:/templates/**");
    }



    @Bean
    public FilterRegistrationBean testFilterRegistration(MyTestFilter myTestFilter) {
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setFilter(myTestFilter);//添加过滤器
        registration.addUrlPatterns("/**");//设置过滤路径，/*所有路径
        //registration.addInitParameter("name", "alue");//添加默认参数
        registration.setName("MyFilter");//设置优先级
        registration.setOrder(1);//设置优先级
        return registration;
    }
}